#pragma once

#include <iostream>
#include <string>
#include <fstream>
#include <fcntl.h>
class Util
{
public:
    // XXXX XXX XXX\r\nYYYYY
    static std::string getOneLine(std::string &buffer, const std::string &sep)
    {
        auto pos = buffer.find(sep);
        if (pos == std::string::npos)
            return "";
        std::string sub = buffer.substr(0, pos);
        // buffer.erase(0, sub.size() + sep.size());
        return sub;
    }
    static bool readFile(const std::string &resource, char *buffer, int size)
    {
        std::ifstream in(resource, std::ios::binary);
        if (!in.is_open())
        {
            std::cerr << "Failed to open file: " << resource << std::endl;
            return false;
        }
        in.read(buffer, size);
        if (in.fail())
        {
            std::cerr << "Failed to read file: " << resource << std::endl;
            in.close();
            return false;
        }
        in.close();
        std::cout << resource << std::endl;
        return true;
    }
    // static bool readFile(const std::string &resource, char *buffer, int size)
    // {
    //     std::ifstream in(resource, std::ios::binary);
    //     if (!in.is_open()) // 资源不存在
    //     {
    //         std::cout << resource << 1111111111 << std::endl;
    //         return false;
    //     }
    //     in.read(buffer, size);
    //     in.close();
    //     std::cout << resource << std::endl;
    //     return true;
    // }
};